package com.alex.zookeeper.crud;

import com.alex.zookeeper.BaseTest;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.data.Stat;
import org.junit.Test;

/**
 * 查看节点
 */
@Slf4j
public class ZKGet extends BaseTest {

    @Test
    public void sync() throws Exception {
        Stat stat = new Stat();
        // agr0: 节点路径
        // arg1: 是否使用连接对象中注册的监视器
        // arg2: 返回znode的元数据
        byte[] data = zooKeeper.getData(PATH, false, stat);
        log.info("data: {}, stat: {}", new String(data), stat);
    }

    @Test
    public void async() {
        zooKeeper.getData(PATH, false, new AsyncCallback.DataCallback() {
            @Override
            public void processResult(int resCode, String path, Object context, byte[] data, Stat stat) {

            }
        }, "get Data");
    }
}
